package com.shundr.shipper.common.view;

import android.app.Dialog;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shundr.shipper.R;

/**
 * 
 * DialogWallet
 * 
 * @author larry 2015-7-1 下午5:13:24 
 * @version 1.0.0
 *
 */
public class DialogWallet extends Dialog {

	private Context mContext;
	private int money;
	private boolean isShow;

	private FlakeView flakeView;

	public DialogWallet(Context context, int money, boolean isShow) {
		super(context, R.style.dialog_style);
		this.mContext = context;
		this.money = money;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.view_wallet);
		flakeView = new FlakeView(mContext);
		TextView tvTips = (TextView) findViewById(R.id.tv_tip);
		TextView tvMoney = (TextView) findViewById(R.id.tv_money);
		tvTips.setText("恭喜您领取" + money + "个积分");
		tvMoney.setText(money + "");
		final LinearLayout container = (LinearLayout) findViewById(R.id.container);
		// 将flakeView 添加到布局中
		container.addView(flakeView);
		// 设置同时出现在屏幕上的金币数量 建议64以内 过多会引起卡顿
		flakeView.addFlakes(10);
		/**
		 * 绘制的类型
		 * 
		 * @see View.LAYER_TYPE_HARDWARE
		 * @see View.LAYER_TYPE_SOFTWARE
		 * @see View.LAYER_TYPE_NONE
		 */
		flakeView.setLayerType(View.LAYER_TYPE_NONE, null);
		findViewById(R.id.btn_ikow).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						if (container != null) {
							container.removeAllViews();
						}
						dismiss();
					}
				});
		
		if(isShow){
			new Handler().postDelayed(new Runnable() {
				
				@Override
				public void run() {
					container.removeAllViews();
				}
			}, 3000);
		}
		this.setCanceledOnTouchOutside(false);
		MediaPlayer player = MediaPlayer.create(mContext, R.raw.shake);
		player.start();
		super.onCreate(savedInstanceState);
	}

}
